define(function(require){
	var $=require("jq");
	var dialogcss=require("/pinzhiV2.0/css/pz-dialog.css");
	var Dialog=require("pz_use_dialog.js");
	
	var levelTypeId = $('#levelTypeId').val();
	var levelName=$("#levelTypeName").val();
	var status = $('#status').val();
	var isAttorney = $('#isAttorney').val();
	
	$(document).ready(function(){
		$("#menu27").on('click',function(){
			  var tips=new PZ_Dialog({
					type:"alert",
					buttonSureText:"知道了",
					text:"提示信息",
					tipsText:"暂未开通，敬请期待",
					mask:0.1,
					isDrag:true                //开起拖动
				});
		 });
		
		$("#menu23").on('click',function(){
	    	if (levelTypeId <= 1) {
	    		if (status == 1) {
	    			var tips=new PZ_Dialog({
	        			type:"alert",
	        			buttonSureText:"知道了",
	        			text:"你现在还是"+levelName,
	        			tipsText:"您当前是"+levelName+"，还不能开通“我的代理”，升级到银卡会员就可以开通啦，加油升级吧！<a href='/helpCenter.do?c_id=144501' style='color:red;'>去了解会员等级权限。</a>",
	        			height:150,
	        			mask:0.1,
	        			isDrag:true                //开起拖动
	        		});
	    			return false;
	    		} else {
	    			var tips=new PZ_Dialog({
	        			type:"alert",
	        			buttonSureText:"知道了",
	        			height:128,
	        			width:350,
	        			text:"你现在还是"+levelName,
	        			tipsText:"您当前是"+levelName+"，还不能申请开通“我的代理”，升级到银卡会员就可以申请啦，加油升级吧！<a href='/helpCenter.do?cid=144501' style='color:red;'>去了解会员等级权限。</a>",
	        			mask:0.1,
	        			isDrag:true                //开起拖动
	        		});
					return false;
	    		}
	    	} else if(isAttorney == 0) {
	    		var prompt=new PZ_Dialog({
					type:"prompt",
					text:"请输入激活码",
					buttonSureText:"激活",
					buttonCancelText:"放弃",
					callBack:function(value){
						$.post("/vipCenter/activeUser.do", {activeCode:value}, function(msg){
							var tips=new PZ_Dialog({
								  type:"tips",
								  text:msg.message,
								  delay:1,			//提示框延时几秒，不提供默认为3秒关闭
								  mask:"transparent"
								  });
							if(msg.ret==1) {
								window.location.href = "/vipCenter/listMyAttorneys.do?menu_id=23";
							}else{
								var tips=new PZ_Dialog({
				        			type:"alert",
				        			buttonSureText:"知道了",
				        			height:128,
				        			width:350,
				        			text:"提示信息",
				        			tipsText:msg.message,
				        			mask:0.1,
				        			isDrag:true                //开起拖动
				        		});
								return false;
							}
						}, "json");
					},
					mask:0.3,
					isDrag:true
				});
	    		return false;
	    	} else if(levelTypeId > 2){
	    		window.location.href = "/vipCenter/listMyAttorneys.do?menu_id=23";
	    	}
			
		});
		
		/***
		 * TAB切换标签页
		 * **/
		(function(){
			var deliveryInfos = window.deliveryInfos||[];
			if(deliveryInfos.length>0){
				//将包裹信息插入到届面上start
				var html = "";
				var tabHtml ="";
				var contentHtml = "";
				var rowLength = 4;
				var insertDom = $("#J_delviery_flag");
				for(var i=0;i<deliveryInfos.length;i++){
					var selected = i==0; 
					var deliveryInfo = deliveryInfos[i];
					var type = deliveryInfo.type;
					tabHtml+='<li '+(selected?'class="current"':'')+'>'+(i+1)+'号包裹</li>';
					contentHtml +='<div class="tab-item'+(selected?' show':'')+'">';
					contentHtml +="<div><p>物流公司："+deliveryInfo.deliveryName+"</p><p>运&nbsp;&nbsp;单&nbsp;&nbsp;号：";
					contentHtml +=deliveryInfo.deliveryNo+"</p></div><div class='pad'>";
					if(type=="infos"){
						var infos = deliveryInfo.infos;
						for(var j=0;j<infos.length;j++){
							contentHtml+=infos[j].time+"&nbsp;&nbsp;"+infos[j].content+"<br>";
						}
					}else if(type=="link"){
						contentHtml+='<a href="'+deliveryInfo.deliveryUrl+'" target="_blank">查看详情</a>';
					}else if(type=="none"){
						contentHtml+='暂无配送信息';
					}
					contentHtml+="</div></div>";
					
					
					//如果到了一行就把html拼上去
					if(i%rowLength==rowLength-1||i==deliveryInfos.length-1){
						html=[
								'<div class="js-tab-view tab-wrap">',
									'<ul class="tab-index clearfix">',
										tabHtml,
									'</ul>',
									'<div class="tab-content">',
										contentHtml,
									'</div>',
									(i<rowLength&&i>0)?"<div class='express-tips'>(由于发货地址不同,一个订单可能会产生多个运单号,请注意查收)</div>":"" ,
								'</div>'
						       ].join("");
						tabHtml="";
						contentHtml = "";
						insertDom = $(html).insertAfter(insertDom);
					}
				}

				var tabsMian = $(".js-tab-view");
				
				var tabInit = function(tab){
					var tabIndexs   = tab.find("ul.tab-index li"),
						tabContents = tab.find("div.tab-item");
					tabIndexs.click(function(){
						$(this).addClass("current").siblings().removeClass("current");
						var idx = $(this).index();
						tabContents.eq(idx).addClass("show").siblings().removeClass("show");
					});
				};
				//初始化页面所以的tab
				$.each(tabsMian,function(i,o){
					tabInit(tabsMian.eq(i));
				});	
			}
		})();
	});
});